package cn.itcast.babasport.controller.brand;

import java.util.List;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import cn.itcast.babasport.pojo.page.Pagination;
import cn.itcast.babasport.pojo.product.Brand;
import cn.itcast.babasport.service.brand.BrandService;

import org.springframework.ui.Model;

@Controller
@RequestMapping("/brand")
public class BrandController {
	@Resource
	private BrandService brandService;
	
	
	/*@RequestMapping("list.do")
	public String list(String name,@RequestParam(defaultValue="1") Integer isDisplay,Model model){
		List<Brand> brands = brandService.selectBrandListNoPage(name, isDisplay);
		model.addAttribute("brands", brands);
		//查询条件回显
		model.addAttribute("isDisplay", isDisplay);
		model.addAttribute("name", name);
		
		return "brand/list";
	}*/
	@RequestMapping("list.do")
	public String list(String name,@RequestParam(defaultValue="1") Integer isDisplay,Model model,Integer pageNo){
		Pagination pagination = brandService.selectBrandListHavePage(name, isDisplay,pageNo);
		model.addAttribute("pagination", pagination);
		//查询条件回显
		model.addAttribute("isDisplay", isDisplay);
		model.addAttribute("name", name);
		model.addAttribute("pageNo", pageNo);
		return "brand/list";
	}
	/**
	 * 根据ID查询商品分类信息
	 * @param name
	 * @param isDisplay
	 * @param model
	 * @param pageNo
	 * @return
	 */
	@RequestMapping("edit.do")
	public String edit(Model model,Long id){
		Brand brand = brandService.selectBrandById(id); 
		model.addAttribute("brand", brand);
		return "brand/edit";
	}
	/**
	 * 更新商品分类
	 * @param model
	 * @param id
	 * @return
	 * @throws Exception 
	 */
	@RequestMapping("update.do")
	public String update(Brand brand) throws Exception{
		 brandService.updateBrand(brand); 
		return "redirect:list.do";
	}
	/**
	 * 跳转到添加页面
	 * @param brand
	 * @return
	 * @throws Exception
	 */
	@RequestMapping("add.do")
	public String add(){
		return "brand/add";
	}
	/**
	 * 添加商品分类信息
	 * @param brand
	 * @return
	 * @throws Exception
	 */
	@RequestMapping("save.do")
	public String save(Brand brand){
		brandService.insertBrand(brand);
		return "redirect:list.do";
	}
	
	/**
	 * 批量删除商品分类信息
	 * @param brand
	 * @return
	 * @throws Exception
	 */
	@RequestMapping("deleteBatchBrand.do")
	public String deleteBatchBrand(Long[] ids){
		brandService.deleteBatchBrand(ids);
		return "redirect:list.do";
	}
	
	
	
	

}
